<?php

namespace Yearnfar\Bundle\H5GameBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

/**
 * @Route("/game")
 * @Template()
 */
class GameController extends Controller
{
    /**
     * 首页
     *
     * @Route("/")
     */
    public function indexAction()
    {
        return array(
                // ...
            );
    }

    /**
     * 排行
     *
     * @Route("/top")
     */
    public function topAction()
    {
        return array(
            // ...
        );
    }


    /**
     * 分类
     *
     * @Route("/category")
     */
    public function categoryAction()
    {
        return array(
            // ...
        );
    }

    /**
     * 详情
     *
     * @Route("/info")
     */
    public function infoAction()
    {
        $request = $this->get('request');
        $gid= $request->get('gid', 0);

        $em = $this->getDoctrine()->getManager();
        $h5game = $em->find('CmsBundle:h5game', $gid);
        if (!$h5game) {
            return [];
        }

        //其他游戏
        $others = $em
            ->createQuery("SELECT h5 FROM CmsBundle:h5game h5 WHERE h5.tid=?1 AND h5.publish=?2 AND h5.deltime=?3 AND h5.id!=?4")
            ->setParameter(1, $h5game->getTid())
            ->setParameter(2, 1)
            ->setParameter(3, 0)
            ->setParameter(4, $gid)
            ->setMaxResults(4)
            ->getResult();

        if (!$others) $others = [];
        return [
            'h5game' => $h5game,
            'others' => $others
        ];
    }

}
